package com.situ.b2c.address.dao;

import java.util.List;

import com.situ.b2c.pojo.Address;
import com.situ.b2c.pojo.Area;
import com.situ.b2c.util.JDBCUtil;

public class AddrDao {
	private static final String SQL_INSERT = "INSERT INTO TB_ADDRESS(USER_ID,USER_NAME,PROVINCE_CODE,CITY_CODE,DISTRICT_CODE,ADDR_NAME,USER_PHONE,ADDR_DEFAULT,CREATE_BY,CREATE_DATE)VALUES(?,?,?,?,?,?,?,?,?,?)";
	private static final String SQL_SELECT = "SELECT * FROM TB_ADDRESS WHERE ACTIVE_FLAG=1 AND USER_ID = ?";
	private static final String SQL_AREA_SELECT = "SELECT * FROM TB_AREA WHERE ACTIVE_FLAG = 1 AND PARENT_CODE = ?";
	private static final String SQL_AREA_NAME = "SELECT * FROM TB_AREA WHERE ACTIVE_FLAG = 1 AND AREA_CODE = ?";
	private static final String SQL_SELECTONE_BY_ROWID = "SELECT * FROM TB_ADDRESS WHERE ACTIVE_FLAG=1 AND ROW_ID = ?";
	
	
	
	
	
	public int insert(Address address) {
		
		return JDBCUtil.executeUpdate(SQL_INSERT, address.getUserId(),address.getUserName(),address.getProvinceCode(),address.getCityCode(),address.getDistrictCode(),address.getAddrName(),address.getUserPhone(),address.getAddrDefault(),address.getCreateBy(),address.getCreateDate());
		
	}
	
	public List<Address> selectAddress(Long userId) {
		
		return JDBCUtil.executeQuery(Address.class, SQL_SELECT, userId);
		
	}
	
	public List<Area> selectAreas(Integer parentCode) {
		return JDBCUtil.executeQuery(Area.class,SQL_AREA_SELECT,parentCode);
	}
	
//	public List<Area> selectAreasName(Integer areaCode){
//		
//		return JDBCUtil.executeQuery(Area.class, SQL_AREA_NAME, areaCode);
//	}
	
	public Address selectOneById(Long rowId) {
		
		return JDBCUtil.executeQuery4One(Address.class, SQL_SELECTONE_BY_ROWID, rowId);
		
	}
	
	
	
}
